from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from apps.questions.models import Question, Reply, Label
from apps.users.models import User


class UserModelSerializer(ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'nickname', 'avatar']


class QuestionsModelSerializer(ModelSerializer):
    labels = serializers.StringRelatedField(many=True, read_only=True)
    user = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = Question
        fields = '__all__'


class SubReplyModelSerializer(ModelSerializer):
    user = UserModelSerializer()

    class Meta:
        model = Reply
        exclude = ['parent', ]


class ReplyModelSerializer(ModelSerializer):
    user = UserModelSerializer()
    subs = SubReplyModelSerializer(many=True)

    class Meta:
        model = Reply
        exclude = ['parent', ]


class LabelModelSerializer(ModelSerializer):
    # questions = QuestionsModelSerializer(many=True)
    class Meta:
        model = Label
        fields = '__all__'
